import ModuleTemplate from '@/utils/ModuleTemplate';
import appService from '@/utils/appService';
import systemConfig from '@/utils/config';

/* eslint-disable */
/** modules名称空间 */
export const namespace = 'contract';
const model = {
	name: namespace,
	/** 基本属性 */
	state: {
		/** 分页数据查询条件 */
		query: {
			currentPage: 1,
			pageSize: 10
		}
	},
	/** 从基本数据派生的数据,getters接收state作为其第一个参数，
	 * 接受其他 getters 作为第二个参数，如不需要，第二个参数可以省略
	 */
	getters: {},
	/** 执行同步操作，包含用于直接修改state的函数 */
	mutations: {},
	/** 异步操作，可调用同步操作函数 */
	actions: {
		// 字典  trade/settlement/admin/property/dictionary
		getMerchantSearchKey(store, payload) {
			return new Promise((resolve, reject) => {
				appService.getRequest(`${config.dataSource}/trade-settlement/admin/property/dictionary`, payload).then((result) => {
					if (result.status === 200) {
						resolve(result);
					} else {
						reject(Error);
					}
				});
			});
		},
		// 商户信息列表
		getMerchandList (store, payload) {
			return new Promise((resolve, reject) => {
				appService.getRequest(`${config.dataSource}/trade-merchant/admin/merchant/findOnlyMerchantList`, payload).then((result) => {
					if (result && result.status === 200) {
						resolve(result);
					} else {
						reject(Error);
					}
				});
			});
		},
		// 全部渠道list
		AllMerchandChannel (store, payload) {
			return new Promise((resolve, reject) => {
				appService.getRequest(`${config.dataSource}/trade-payment/admin/paymentChannel/getList`, payload).then((result) => {
					if (result.status === 200) {
						resolve(result);
					} else {
						reject(Error);
					}
				});
			});
		},
		// 组织列表
		getInstitutionalList (store, payload) {
			return new Promise((resolve, reject) => {
				appService.getRequest(`${config.dataSource}/trade-merchant/admin/organization/findPageList`, payload).then((result) => {
					if (result.status === 200) {
						resolve(result);
					} else {
						reject(Error);
					}
				});
			});
		},
		/** 按商户号和支付渠道查询商品总数 */
		getMerchandNum (store, payload) {
			return new Promise((resolve, reject) => {
				appService.getRequest(`${config.dataSource}/trade-merchant/api/product/getProductQty`, payload).then((result) => {
					if (result.status === 200) {
						resolve(result);
					} else {
						reject(Error);
					}
				});
			});
		},
		/** 导出 */
		exportExcel (store, payload) {
			return new Promise((resolve, reject) => {
				appService.postRequest(`${config.dataSource}/trade-settlement/admin/merchant/contract/export`, payload, { responseType: 'arraybuffer' }).then((result) => {
					if (result.status === 200) {
						resolve(result);
					} else {
						reject(Error);
					}
				});
			});
		}
	},
	/** 子模块 */
	modules: {}
};
const config = {
	/** 数据源，对应后端controller类的请求映射,
	 * 如果不指定则默认和name一样
	 */
	/* eslint-disable */
	dataSource: systemConfig.serverProxy ,
	// dataSource: systemConfig.tradeInvoicePath,
	invoiceServer: true,
	/** query函数调用的后端controller方法的请求映射 */
	queryMethod: '/trade-settlement/admin/merchant/contract/findPageList',
	localUpdateMethod: '/trade-settlement/admin/merchant/contract/',
	deleteMethod: '/trade-settlement/admin/merchant/contract/',
	saveMethod: '/trade-settlement/admin/merchant/contract/',
	getDetailMethod: '/trade-settlement/admin/merchant/contract/'
};
const moduleTemplate = new ModuleTemplate(model, config);
export const module = moduleTemplate.createModel();
